<template>
    <div>
        <van-row>
            <!-- 居中 -->
            <van-row type="flex" justify="center">
                <van-col span="9">
                    <img alt="Vue logo" width="150" height="150" src="../assets/zut.png">
                </van-col>
            </van-row>
        </van-row>

        <van-row>
            <van-form @submit="onSubmit">
                <van-field
                        v-model="username"
                        label="用户名"
                        disabled
                />
                <van-field
                        v-model="newPassword"
                        type="password"
                        label="新密码"
                        :rules="[{ required: true, message: '请填写新密码' }]"
                />
                <van-field
                        v-model="repeatPassword"
                        type="password"
                        label="重复密码"
                        :rules="[{ required: true, message: '请重复填写新密码' }]"
                />
                <div style="margin: 16px;">
                    <van-button round block type="info" native-type="submit">
                        确认
                    </van-button>
                </div>
            </van-form>
        </van-row>
    </div>
</template>
<script>
    export default {
        created() {

        },
        data() {
            return {
                username:this.$route.query.username,
                newPassword : '',
                repeatPassword : '',
            };
        },
        methods: {
            onSubmit() {
                if (this.newPassword===this.repeatPassword){
                    let user = {
                        username: this.username,
                        password: this.newPassword
                    };
                    this.changePassword(user)
                }else{
                    this.$notify("重复填写新密码错误");
                }

            },
            changePassword(user){
                this.$http.login.changePassword(user).then((res) => {
                    if (res.flag==true){
                        this.$notify("修改成功");
                        this.exit()
                    }
                    else {
                        this.$notify("修改失败");
                    }
                })
            },
            exit(){
                let time = new Date();
                time.setTime(time.getTime()- 1);
                window.document.cookie = `userName=${window.btoa(null)}; path=/; expires=${time.toGMTString()}`;
                window.document.cookie = `passWord=${window.btoa(null)}; path=/; expires=${time.toGMTString()}`
                this.$router.push({path:'/login'})
            },
        },
    };
</script>
<style >

</style>
